package written.test;

import java.util.Scanner;

public class Huawei2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int row = sc.nextInt();
        int col = sc.nextInt();
        t = sc.nextInt();
        int[][] grid = new int[row][col];
        for(int i = 0; i < row; i++){
            for(int j =0; j < col; j++){
                grid[i][j] = sc.nextInt();
            }
        }
        dfs(grid, 0, 0, 0);

        System.out.println(max);
    }
    static int max = -1;
    static int t;
    public static void dfs(int[][] grid, int i, int j, int sum){
        if(i>=grid.length||j>=grid[0].length) return;
        if(i==grid.length-1 && j==grid[0].length-1){
            if(grid[i][j] + sum > t) return;
            else max = Math.max(max, sum+grid[i][j]);
        }
        sum += grid[i][j];
        if(sum > t)  return ;
        dfs(grid, i+1, j, sum);
        dfs(grid, i, j+1, sum);
        return;
    }
}
